import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Req,
} from '@nestjs/common';
import { ProjService } from './proj.service';
import { CreateProjDto } from './dto/create-proj.dto';
import { UpdateProjDto } from './dto/update-proj.dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('proj')
export class ProjController {
  constructor(private readonly projService: ProjService) {}

  @Post()
  @UseGuards(AuthGuard('jwt'))
  create(@Body() createProjDto: CreateProjDto, @Req() req: any) {
    const username = req.user.name;
    return this.projService.create(createProjDto, username);
  }

  @Get()
  @UseGuards(AuthGuard('jwt'))
  findAll(@Req() req: any) {
    const userId = req.user.id;
    return this.projService.findAll(userId);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.projService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateProjDto: UpdateProjDto) {
    return this.projService.update(+id, updateProjDto);
  }

  @Delete(':id')
  @UseGuards(AuthGuard('jwt'))
  remove(@Param('id') id: string) {
    return this.projService.remove(+id);
  }
}
